package com.kcht.sylyg08.dao.impl;

import com.kcht.adp.common.log.Logger;
import com.kcht.sylyg08.dao.DataSourceBaseDao;
import com.kcht.sylyg08.dao.IMaterialContainerBoundDao;
import com.kcth.sylyg08.entity.MaterialContainerBound;

import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import java.util.List;

/**
  *
  * @Package:        com.kcht.sylyg08.dao.impl
  * @Description:     java类作用描述
  * @Author:         lenovo
  * @CreateDate:     2019/5/15 14:07
 */
@Singleton
@Startup
public class MaterialContainerBoundDao extends DataSourceBaseDao<MaterialContainerBound, Long> implements IMaterialContainerBoundDao {
    @Inject
    private Logger log;

    @Override
    public MaterialContainerBound getByContainerId(String containerId) {
        return this.selectOneByJPQL("select a from MaterialContainerBound a where a.containerId=?", containerId);
    }

    @Override
    public List<MaterialContainerBound> getByMaterial(String material) {
        return this.selectListByJPQL("select a from MaterialContainerBound a where a.material= '" + material + "'");
    }

    @Override
    public String getContainerId(String material) {
        return this.selectOneByJPQL("select a.containerId from MaterialContainerBound where a.materials like '%?%'", material);
    }

    @Override
    public Integer getCountByMaterial(String material) {
        return this.selectOneBySQL(
                "select a.a-b.b count from (select sum(count) a " +
                        "from t_syly_materialcontainerbound where material='" + material + "') a , " +
                        "(select ifnull(sum(count),0) b from t_syly_task where status = 0 and material='" + material + "') b",
                MaterialContainerBound.class).getCount();
    }


}
